/*
 @coding  : utf-8
 @Time    : 2023/4/20 15:28
 @Author  : Rumou
 @File    : 水仙花数.go
 @Description:计算1000以内的水仙花数
*/

package main

import (
	"fmt"
	"math"
	"strconv"
)

func main() {
	NarcissisticNumbers := make([]int, 0)
	for num := 100; num <= 1000; num++ {
		numStr := strconv.Itoa(num) //num int => numStr string
		digitCount := len(numStr)   // 数字位数
		total := 0
		for _, oneNumByte := range numStr {
			oneNumInt, _ := strconv.Atoi(string(oneNumByte)) //oneNumByte byte => string => int
			total += int(math.Pow(float64(oneNumInt), float64(digitCount)))
		}
		if total == num {
			NarcissisticNumbers = append(NarcissisticNumbers, num) //符合水仙花数，追加到列表
		}
	}
	for i := 0; i < len(NarcissisticNumbers); i++ { //遍历输出
		fmt.Println(NarcissisticNumbers[i])
	}
}
